﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace doveData.XmlScripts
{
    public class XMLOperate
    {
        /// <summary>
        /// 适用于Hotel,Food,Market的删除操作，重置剩余元素的id
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="findElement"></param>
        public void ResetID(XElement xml,XElement findElement)
        {
            var idList = from q in xml.Elements()
                         where
                         q.Attribute("id") != null
                         select q;
            var ids = from q in idList
                      where
                      int.Parse(q.Attribute("id").Value) > int.Parse(findElement.Attribute("id").Value)
                      select q;
            Console.WriteLine(idList.Count());
            Console.WriteLine(ids.Count());
            if (ids.Count() > 0)
            {
                foreach (var p in ids)
                {
                    if (p.Attribute("id") != null)
                    {
                        string i = (int.Parse(p.Attribute("id").Value) - 1).ToString();
                        p.Attribute("id").SetValue(i);
                    }
                }
            }
        }
    }
}
